﻿@using System.Collections.Specialized
@{
    ViewBag.Title = "Crear Item a partir de datos de usuarios";
}
<script type="text/javascript"> 
   
    @for (int l = 1; l < 100; l++)
    {
        var Fields = "#field" + l;
        var Field = "field" + l;
        var FieldsAction = "#fieldaction" + l;
        var FieldsGroup = "#group" + l;



        var searches = "#searchfield" + l;
        var search = "searchfield" + l;
        var oper = "#operator" + l;

        var groups = "#group" + l;
        var group = "group" + l;
        //var FieldsGroup = "#fieldgroup" + l;
        <text> $(function () { 

            $.getJSON("/ItemData/ListFields", null, function (data) {
                var items = "<option>Seleccione una opcion</option>";
                $.each(data, function (i, item) {
                    items += "<option value=" + item + ">" + item + "</option>";
                });
                $("@Fields").html(items);
            });

            $.getJSON("/ItemData/ListSearchFields", null, function (data) {
                var items = "<option>Seleccione una opcion</option>";
                $.each(data, function (i, item) {
                    items += "<option value=" + item + ">" + item + "</option>";
                });
                $("@searches").html(items);
            });

             $.getJSON("/ItemData/ListGroupFields", null, function (data) {
                var items = "<option>Seleccione una opcion</option>";
                $.each(data, function (i, item) {
                    items += "<option value=" + item + ">" + item + "</option>";
                });
                $("@groups").html(items);
            });
        
            $("@searches").change(function () {

            var Param = { field: $("@searches > option:selected").attr("value") , campo: '@search'};
            $.getJSON("/ItemData/ListOperators/", Param, function (data) {
                var items = "<option>Operacion</option>";
                $.each(data, function (i, item) {
                    items += "<option value=" + item + ">" + item + "</option>";
                });
                $("@oper").html(items);
            });
        });
 
            $("@Fields").change(function () {

            var Param = { field: $("@Fields > option:selected").attr("value") , campo: '@Field'};
            $.getJSON("/ItemData/ListActions/", Param, function (data) {
                var items = "<option>Seleccione una opcion</option>";
                $.each(data, function (i, item) {
                    items += "<option value=" + item + ">" + item + "</option>";
                });
                $("@FieldsAction").html(items);
            });
        });

    
    });

        </text>
       
    }
        
        
    
    
    $(function () {
        $.getJSON("/ItemData/ListLogic", null, function (data) {
            var items = "<option>Condicion</option>";
            $.each(data, function (i, item) {
                items += "<option value=" + item + ">" + item + "</option>";
            });
            $(".classlogic").html(items);
        });

    });
    
   
    
    
    

    var indicecontainerfield = 1;
    var indicecontaionersearch = 1;
    var indicecontainergroup = 1;
    
    function hide(id) {

        var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
        elDiv.style.display = 'none';
        

    }

    function show(id) {

        var elDiv = document.getElementById(id); //se define la variable "elDiv" igual a nuestro div
        elDiv.style.display = 'block';

    }
    
    function shownext(id) {
        var b = '';
        if (id == 'containerfield') {
            indicecontainerfield++;
            b = indicecontainerfield + '';
        }
        
        if (id == 'containergroup') {
            indicecontainergroup++;
            b = indicecontainergroup + '';
        }
        
        if (id == 'containersearch') {
            indicecontaionersearch++;
            b = indicecontaionersearch + '';
        }
        
        
        var elDiv = document.getElementById(id+b); //se define la variable "elDiv" igual a nuestro div
        elDiv.style.display = 'block';

    }
    
    function hidenext(id) {
        //alert(indice);
        if (indice != 1) {
            var b = indice + '';
            var elDiv = document.getElementById(id+b); //se define la variable "elDiv" igual a nuestro div
            elDiv.style.display = 'none';
            indice--;
        }
    }
    
    function changeindex(id) {
        document.getElementById(id).selectedIndex = 0;
    }
    
    function changevalue(id) {
        document.getElementById(id).value = '';
        document.getElementById(id).Text = '';
    }
    

    window.onload = function(){/*hace que se cargue la función */

        @{
            for (int j = 2; j < 100; j++)
            {
                string name = "containerfield" + j;
                string sname = "containersearch" + j;
                string gname = "containergroup" + j;
                @:hide('@name');
                @:hide('@sname');
                @:hide('@gname');
                
            }
       }

    };

</script>
<script type="text/javascript">

   

    function addElement(text) {

        var divelement = document.getElementById("container");
        var select = document.createElement("select");
        select.className = text;
        divelement.appendChild(select);

    }
</script>



<div class="grid">

    <div class="c12">
        <div class="alert error">@TempData["Error"]</div>
       <h2>Seleccione los criterios de selección de los datos</h2>

    </div>

    <div class="c12">
    
        <div class="c9 first" id=”contenido”>
        
            <div id="fields">
                @using (Html.BeginForm())
                {
                    
                    <h3>Escoja los campos a mostrar</h3>
                    
                    <div id="containerfield1">
                        <div class="c12">
                            <div class="c5 first">
                                Seleccionar todos los campos @Html.CheckBox("AllFields", false)
                            </div>
                            <div class="c5">
                                Contar registros @Html.CheckBox("CountFields", false)
                            </div>
                        </div>
                        <br/>
                        <br/>
                            
                        <div class="c12">
                            <div class="c1 first"> 
                                <p style="font-size: 12px">Campo 1</p>
                            </div>
                            <div class="c3">
                                @Html.DropDownList("field1", new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classfield" })
                            </div>
                            <div class="c3">
                                @Html.DropDownList("fieldaction1", new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classfieldaction" })
                            </div>
                            <div class="c1 first">
                                <input type="button" onClick="shownext('containerfield')" value="" class="Ibtnadd"/>
                            </div>
                        </div>
                    </div>

                    for (int i = 2; i < 100; i++)
                    {
                        string nid = "containerfield" + i;
                        string showaction = "containerfield" + (i + 1);
                        string hideaction = "containerfield" + i;
                        string indice = "field" + i;
                        string indiceaction = "fieldaction" + i;
                        <div id="@nid">
                            <div class="c12">
                                <div class="c1 first">
                                    <p style="font-size: 12px">Campo @i</p>
                                </div>
                                <div class="c3">
                                    @Html.DropDownList("field" + i, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classfield" })
                                </div>
                                <div class="c3">
                                    @Html.DropDownList("fieldaction" + i, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classfieldaction" })
                                </div>
                                @*<div class="c1 first">
                                        <input type="button" onClick="show('@showaction');" value="+"/>                                       
                                    </div>*@
                                <div class="c1 first">
                                    <input type="button" onClick="hide('@hideaction'); changeindex('@indice'); changeindex('@indiceaction');" value="" class="Ibtndelete"/>
                                </div>
                            </div>             
                        </div>
                    
                    
                    }
                        
                    <h3>Escoja los criterios de busqueda</h3>
                    <div id="containersearch1">
                        <div class="c12">
                            <div class="c2 first"> 
                                     
                            </div>
                                 
                            <div class="c3">
                                @Html.DropDownList("searchfield1", new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classsearchfield" })
                            </div>
                            <div class="c2">
                                @Html.DropDownList("operator1", new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classoperators" })
                            </div>
                                 
                            <div class="c3">
                                @Html.Editor("criteria1")
                                @*<input type="text" id="criteria1" style="width: 100px"/>*@
                            </div>
                                 
                            <div class="c2 first">
                                <input type="button" onClick="shownext('containersearch');" value="" class="Ibtnadd"/>
                            </div>
                        </div>
                    </div>

                    for (int k = 2; k < 100; k++)
                    {
                        string sid = "containersearch" + k;
                        string nextsid = "containersearch" + (k + 1);
                        string nextsearchfield = "searchfield" + (k + 1);
                        string searchfield = "searchfield" + k;
                        string operatorfield = "operator" + k;
                        string criteria = "criteria" + k;
                        string logic = "logic" + k;
                        <div id="@sid">
                            <div class="c12">
                                <div class="c2 first">
                                    @Html.DropDownList("logic" + k, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classlogic" })                                    
                                </div>
                                            
                                <div class="c3">
                                    @Html.DropDownList("searchfield" + k, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classsearchfield" })
                                </div>
                                <div class="c2">
                                    @Html.DropDownList("operator" + k, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classoperators" })
                                </div>
                                 
                                <div class="c3">
                                    @Html.Editor(criteria)
                                    @*<input type="text" id="@criteria" style="width: 100px"/>*@
                                </div>
                                 
                                @*<div class="c1 first">
                                        <input type="button" onClick="show('@nextsid');" value="+"/> 
                                        
                                    </div>*@
                                <div class="c2 first">
                                    <input type="button" onClick="hide('@sid'); changeindex('@searchfield'); changeindex('@operatorfield'); changevalue('@criteria'); changeindex('@logic');" value="" class="Ibtndelete"/>
                                </div>
                            </div>
                        </div>
                    
                            
                            
                    }
                        
                    <h3>Escoja los criterios de agrupamiento</h3>
                    <div id="containergroup1">
                        <div class="c12">
                            <div class="c2 first">
                                <p style="font-size: 12px">Agrupar por</p>
                            </div>
                            <div class="c5">
                                @Html.DropDownList("group1", new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classgroup" })                                    
                            </div>
                            <div>
                                <div class="c1 first">
                                    <input type="button" onClick="shownext('containergroup')" value="" class="Ibtnadd"/>
                                </div>
                            </div>
                                    
                        </div>
                    </div>

                    for (int m = 2; m < 100; m++)
                    {
                        var group = "containergroup" + m;
                        var grouplist = "group" + m;
                        <div id="@group">
                            <div class="c12">
                                <div class="c2 first">
                                    <p style="font-size: 12px">Agrupar por</p>
                                </div>
                                <div class="c5">
                                    @Html.DropDownList("group" + m, new SelectList(new ListDictionary()), htmlAttributes: new { @class = "classgroup" })                                    
                                </div>
                                <div class="c1 first">
                                    <input type="button" onClick="hide('@group'); changeindex('@grouplist');" value="" class="Ibtndelete"/>
                                </div>
                            </div>
                        </div>
                    }
                    <h3>Descripcion del item</h3>
                    <div class="c12">
                        @Html.TextArea("Sentence", htmlAttributes: new {@style = "width: 500px; height : 100px;"})
                    </div>
                    
                        <h3>Tipo de grafico</h3>
                        <div class="c12">
                            <div class="c1 first">
                        
                            </div>
                            <div class="c11">
                                <div class="c12">
                                    @Html.RadioButton("option", "Pastel") Pastel
                                </div>
                                <div class="c12">
                                    @Html.RadioButton("option", "Barras") Barras
                                </div>
                                <div class="c12">
                                    @Html.RadioButton("option", "Ninguno") Sin grafico
                                </div>
                           
                            </div>
                            <h3>Opciones</h3>
                            <div class="c12">
                                <div class="c2">
                                    <p style="font-size: 13px">Numero de Pagina</p>
                                </div>
                                <div class="c9">
                                    @Html.TextBox("numeropagina", "")
                                </div>
                            </div>                  
                        </div>
                        <input type="submit" value="Guardar"/>
                    
                        }

                    </div>
            
            
          
        </div>
        
        

        <div class="c3 last" id=”layoutderecho”>@Html.Partial("_LayoutSideBar")</div>

    </div>

    &nbsp;
</div>



